package com.homegoods.classify.presenter;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.classify.ui.view.IView;
import com.homegoods.aroutercomment.ARouterPath;
import com.homegoods.home.model.HomeGroupsModel;
import com.kedll.library.mvp.BasePresenter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author QiQi
 * @ClassName: ClassifyListActivityPresent
 * @date 2018/9/7
 * @description
 */
public class ClassifyListActivityPresent extends BasePresenter<IView> {
    public ClassifyListActivityPresent(IView mView) {
        super(mView);
    }

    //TODO
    public void onLoadData(List<HomeGroupsModel.ChildrenBean> childlist) {
        if (childlist.size() == 0) {
            return;
        }
        List<Fragment> fragments = new ArrayList<>();
        String[] titles = new String[childlist.size()];
        for (int i = 0; i < childlist.size(); i++) {
            HomeGroupsModel.ChildrenBean child = childlist.get(i);
            titles[i] = child.getGroupName();
            Fragment fragment = (Fragment) ARouter.getInstance().build(ARouterPath.PATH_HOME_FRAGMENT_CLASSIFY).navigation();
            Bundle bundle = new Bundle();
            bundle.putSerializable("child", child);
            fragment.setArguments(bundle);
            fragments.add(fragment);
        }
        mView.initViewPager(fragments, titles);
    }
}
